﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Assessment.Management.SharedComponent.Params.CommonParam;
using Assessment.Management.SharedComponent.Entities;

namespace Assessment.Management.DAO.CommonManagers
{
    public class QuestionStudentDAO : BaseDaos
    {
        public QuestionStudentDAO()
            : base()
        {
        }
        public void InsertAnswerOfQuestion(QuestionStudentParam param)
        {
            string query = @"Insert into Question_Student (Answer, QuestionID, ClassID, SubjectID) 
                                        values(@Answer, @QuestionID, @ClassID, @SubjectID)";

            var cmd = base.GetSqlCommand();
            cmd.CommandText = query;
            cmd.Parameters.AddWithValue("@Answer", param.QuestionStudent.Answer);
            cmd.Parameters.AddWithValue("@QuestionID", param.QuestionStudent.QuestionID);
            cmd.Parameters.AddWithValue("@SubjectID", param.QuestionStudent.SubjectID);
            cmd.Parameters.AddWithValue("@ClassID", param.QuestionStudent.ClassID);


            try
            {
                int count = base.ExecuteNonQuery(cmd);
            }
            finally
            {
                base.CloseConnection(cmd);
            }
        }
        public void GetListAnswerByQuestionIDSubjectIDClassID(QuestionStudentParam param)
        {
            string query = @"Select * from Question_Student 
                                        where QuestionID=@QuestionID and 
                                                ClassID = @ClassID and SubjectID = @SubjectID";

            var cmd = base.GetSqlCommand();
            cmd.CommandText = query;
            cmd.Parameters.AddWithValue("@QuestionID", param.QuestionStudent.QuestionID);
            cmd.Parameters.AddWithValue("@SubjectID", param.QuestionStudent.SubjectID);
            cmd.Parameters.AddWithValue("@ClassID", param.QuestionStudent.ClassID);
            try
            {
                param.listQuestionStudent = base.ExecuteQueryGetListObject<QuestionStudent>(cmd);
            }
            finally
            {
                base.CloseConnection(cmd);
            }
        }

    }
}
